import { fetchMerchants, fetchStores, } from '@/services/distribution/whole';
const DistributionModel = {
  namespace: 'distribute',
  state: {
    merchants: [],
    stores: [],
    inform: {},
  },
  effects: {
    // 商户
    *fetchMerchants(_, { call, put, select }) {
      const data = yield call(fetchMerchants);
      yield put({
        type: 'saveData',
        payload: {
          merchants: data.data
        },
      });
    },
    // 门店
    *fetchStores({payload}, { call, put, select }) {
      const data = yield call(fetchStores, payload);
      yield put({
        type: 'saveData',
        payload: {
          stores: data.data
        },
      });
    },
  },
  reducers: {
    saveData(state, { payload }) {
      return {
        ...state,
        ...payload
      }
    },
  },
  subscriptions: {
    setup({ history }) {
      // Subscribe history(url) change, trigger `load` action if pathname is `/`
    },
  },
};
export default DistributionModel;
